entry: Select word on double tap
authorMatthias Clasen <mclasen@redhat.com>
Wed, 10 Jun 2015 10:20:18 +0000 (06:20 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 10 Jun 2015 10:20:18 +0000 (06:20 -0400)
The same approach as taken for GtkTextView in the previous commit.

gtk/gtkentry.c

index 26d5b1210ed23956e2213f303d546413d3a4b6c5..c1b3ab71941c4fc9432c3815a53198734ae4bc26 100644 (file)
@@ -202,6 +202,8 @@ struct _GtkEntryPrivate
   guint16       preedit_length;              /* length of preedit string, in bytes */
   guint16      preedit_cursor;              /* offset of cursor within preedit string, in chars */
 
+  gint64        handle_place_time;
+
   guint         shadow_type             : 4;
   guint         editable                : 1;
   guint         in_drag                 : 1;
@@ -4513,6 +4515,7 @@ gtk_entry_multipress_gesture_pressed (GtkGestureMultiPress *gesture,
               if (!extend_selection)
                 {
                   gtk_editable_set_position (editable, tmp_pos);
+                  priv->handle_place_time = g_get_monotonic_time ();
                 }
               else
                 {
@@ -6740,12 +6743,26 @@ gtk_entry_handle_drag_finished (GtkTextHandle         *handle,
                                 GtkTextHandlePosition  pos,
                                 GtkEntry              *entry)
 {
-  if (!entry->priv->cursor_handle_dragged &&
-      !entry->priv->selection_handle_dragged)
-    gtk_entry_selection_bubble_popup_set (entry);
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (!priv->cursor_handle_dragged && !priv->selection_handle_dragged)
+    {
+      GtkSettings *settings;
+      guint double_click_time;
+
+      settings = gtk_widget_get_settings (GTK_WIDGET (entry));
+      g_object_get (settings, "gtk-double-click-time", &double_click_time, NULL);
+      if (g_get_monotonic_time() - priv->handle_place_time < double_click_time * 1000)
+        {
+          gtk_entry_select_word (entry);
+          gtk_entry_update_handles (entry, GTK_TEXT_HANDLE_MODE_SELECTION);
+        }
+      else
+        gtk_entry_selection_bubble_popup_set (entry);
+    }
 
-  if (entry->priv->magnifier_popover)
-    gtk_widget_hide (entry->priv->magnifier_popover);
+  if (priv->magnifier_popover)
+    gtk_widget_hide (priv->magnifier_popover);
 }